import { CacheModule, Global, Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { LocalCacheService } from './local-cache.service';
import * as redisStore from 'cache-manager-redis-store';

@Global()
@Module({
  imports : [
    CacheModule.registerAsync({
      isGlobal : true,
      useFactory: async (configService: ConfigService) => ({
        store: redisStore,
        ...configService.get('local.redis')
      }),
      inject: [ConfigService],
    }),
  ],
  providers: [LocalCacheService],
  exports : [LocalCacheService]
})
export class LocalCacheModule {}
